23 Juni 2017
ggplot und ggmapggplot2ggplot2 installieren und ladeninstall.packages("ggplot2")
library(ggplot2)
diamonds Datensatzhead(diamonds)
| carat | cut | color | clarity | depth | table | price | x | y | z |
|---|---|---|---|---|---|---|---|---|---|
| 0.23 | Ideal | E | SI2 | 61.5 | 55 | 326 | 3.95 | 3.98 | 2.43 |
| 0.21 | Premium | E | SI1 | 59.8 | 61 | 326 | 3.89 | 3.84 | 2.31 |
| 0.23 | Good | E | VS1 | 56.9 | 65 | 327 | 4.05 | 4.07 | 2.31 |
| 0.29 | Premium | I | VS2 | 62.4 | 58 | 334 | 4.20 | 4.23 | 2.63 |
| 0.31 | Good | J | SI2 | 63.3 | 58 | 335 | 4.34 | 4.35 | 2.75 |
| 0.24 | Very Good | J | VVS2 | 62.8 | 57 | 336 | 3.94 | 3.96 | 2.48 |
qplotqplot wird für schnelle Graphiken verwendet (quick plots)ggplot kann man alles bis ins Detail kontrollieren# histogram qplot(depth, data=diamonds)
qplot(cut, depth, data=diamonds)
qplot(factor(cyl), data=mtcars,geom="bar")
qplot(data=diamonds,x=cut,y=depth,geom="boxplot")
# scatterplot qplot(carat, depth, data=diamonds)
qplot(carat, depth, data=diamonds,color=cut)
myGG<-qplot(data=diamonds,x=carat,y=depth,color=carat) myGG + stat_smooth(method="lm")
qplot(factor(cyl), data=mtcars, geom="bar") + coord_flip()
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
Es wird das Paket RColorBrewer verwendet um die Farbpalette zu ändern
install.packages("RColorBrewer")
library(RColorBrewer)
myColors <- brewer.pal(5,"Accent")
names(myColors) <- levels(diamonds$cut)
colScale <- scale_colour_manual(name = "cut",
values = myColors)
p <- ggplot(diamonds,aes(carat, depth,colour = cut)) + geom_point() p + colScale
ggsave("Graphik.jpg")
Noam Ross - Quick Introduction to ggplot2
Arten von räumlichen Daten:
Das R-paket ggmap wird im folgenden genutzt um verschiedene Kartentypen darzustellen.
Mit qmap kann man eine schnelle Karte erzeugen.
ggmap:devtools::install_github("dkahle/ggmap")
devtools::install_github("hadley/ggplot2")
install.packages("ggmap")
librarylibrary(ggmap)
Und schon kann die erste Karte erstellt werden:
qmap("Mannheim")
BBT <- qmap("Berlin Brandenburger Tor")
BBT
qmap("Germany")
qmap("Germany", zoom = 6)
?qmap
Verschiedene Abschnitte in der Hilfe:
Ausschnitt aus der Hilfe Seite zum Befehl qmap:
qmap Example
Das Beispiel kann man direkt in die Konsole kopieren:
# qmap("baylor university")
qmap("baylor university", zoom = 14)
# und so weiter
qmap("Mannheim", zoom = 12)
qmap('Mannheim', zoom = 13)
qmap('Mannheim', zoom = 20)
qmap('Mannheim', zoom = 14, maptype="satellite")
qmap('Mannheim', zoom = 20, maptype="hybrid")
qmap("Mannheim", zoom = 14, maptype="hybrid")
Aus Physischen Karten kann man Informationen über Berge, Flüsse und Seen ablesen.
Farben werden oft genutzt um Höhenunterschiede zu visualisieren
qmap('Schriesheim', zoom = 14,maptype="terrain")

New York
qmap('Mannheim', zoom = 14,maptype="watercolor",source="stamen")
qmap('Mannheim', zoom = 14,
maptype="toner",source="stamen")
qmap('Mannheim', zoom = 14,
maptype="toner-lite",source="stamen")
qmap('Mannheim', zoom = 14,
maptype="toner-hybrid",source="stamen")
qmap('Mannheim', zoom = 14,
maptype="terrain-lines",source="stamen")